import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { DefaultService } from '../../api';
import { HttpClient } from '@angular/common/http';

@Component({
  selector: 'app-wechat-bind',
  templateUrl: './wechat-bind.component.html',
  styleUrls: ['./wechat-bind.component.css']
})
export class WechatBindComponent implements OnInit {
  openId:string;
  constructor(private router:ActivatedRoute,private next:Router,private api:DefaultService,private http:HttpClient) { }

  ngOnInit() {
    this.router.params.subscribe(value=>{
      this.openId = value['openId'];
      this.api.getUser().subscribe(user=>{
        if(user.username==undefined){
          this.next.navigateByUrl('/login?go=/device/detail/'+this.openId);
        }else{
          this.api.bindWechat(this.openId).subscribe(v=>{
            console.log(v)
          })
        }
      });
    });
  }

}
